using System;
using System.Xml;
using System.Collections;

namespace ScenarioFramework.Modules.FormHelper
{

	
	public class XMLResource : bOSdotNET.XML.Data.XMLObject
	{
		//public const string MAIN_NODE	= "Resource";

		public const string ID_ATTRIBUTE			= "Id";
		
		public const string SQL_NODE				= "SQL";
		public const string PROCESSATTRIBUTE_NODE	= "ProcessAttribute";
		public const string XSLT_NODE				= "XSLT";
		public const string DOCUMENT_NODE			= "Document";
		public const string NAME_DOCUMENT_ATTRIBUTE	= "Name";
		
		private string sId = string.Empty;
		private string sNameDoc = string.Empty;
		private string sMainNodeName= string.Empty;
		private string sMainNodeValue= string.Empty;
		
		public XMLResource()
		{
			this.Init();
		}

		/** CONSTRUCTOR Width XML parsering**/
		public XMLResource(System.Xml.XmlNode node)
		{
			this.Parse(node);
		}

		override public void Init()
		{
			this.sId= string.Empty;
			this.sNameDoc= string.Empty;
			this.sMainNodeValue= string.Empty;
			this.sMainNodeName= string.Empty;
			
		}

		/** PROPERTIES **/


		public string NameNode 
		{
			get { return this.sMainNodeName; }
			set { this.sMainNodeName = value; }
		}

		public string NodeValue
		{
			get { return this.sMainNodeValue; }
			set { this.sMainNodeValue = value; }
		}

		public string Id 
		{
			get { return sId; }
			set { sId = value; }
		}

		public string NameDoc
		{
			get { return sNameDoc; }
			set { sNameDoc = value; }
		}

				
		/** INSTANCE METHODS **/

		/** Parsering method for filling the entity **/
		override public void Parse(System.Xml.XmlNode node2Parse)
		{
			this.Init();

			System.Xml.XmlNode node;
			

			/** find the name of the root tag **/
			
			switch (node2Parse.Name) 
			{
				case XMLResource.DOCUMENT_NODE:
					this.sMainNodeName=XMLResource.DOCUMENT_NODE;
					sMainNodeValue=node2Parse.InnerText;
					break;
				case XMLResource.PROCESSATTRIBUTE_NODE:
					this.sMainNodeName=XMLResource.PROCESSATTRIBUTE_NODE;
					sMainNodeValue=node2Parse.InnerText;
					break;
				case XMLResource.SQL_NODE:
					this.sMainNodeName=XMLResource.SQL_NODE;
					sMainNodeValue=node2Parse.InnerText;
					break;
				case XMLResource.XSLT_NODE:
					this.sMainNodeName=XMLResource.XSLT_NODE;
					sMainNodeValue=node2Parse.InnerText;
					break;
			} 

			for ( int i=0; i<node2Parse.Attributes.Count;i++)
			{
				node = node2Parse.Attributes.Item(i);

				switch ( node.Name )
				{
					case XMLResource.ID_ATTRIBUTE:
						sId = node.InnerText;
						break;
					case XMLResource.NAME_DOCUMENT_ATTRIBUTE:
						if (node2Parse.Name== XMLResource.DOCUMENT_NODE)
                            this.sNameDoc=node.InnerText;
						break;
								
				}
			}
	
		}

		override public bOSdotNET.XML.XMLNode GetXMLNode()
		{
			bOSdotNET.XML.XMLNode xmlNode = new bOSdotNET.XML.XMLNode(this.sMainNodeName,this.sMainNodeValue);
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute (XMLResource.ID_ATTRIBUTE, sId) );
			xmlNode.AddAttribute ( new bOSdotNET.XML.XMLAttribute (XMLResource.NAME_DOCUMENT_ATTRIBUTE, sNameDoc) );
			
						
			return xmlNode;
		}


	}
}
